package com.mxl.service.channel.strategy.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.mxl.common.helper.InterfaceType;
import com.mxl.dao.channel.model.DealResponse;
import com.mxl.service.channel.strategy.ChannelResponseParseStrategy;

/**
 * 19pay处理反馈结果和查询结果的类
 * 
 * @author xianglin.mo
 * 
 */
@Service("new6ResponseParseStrategy")
public class pay19ResponseParseStrategy implements ChannelResponseParseStrategy {
	private static final Logger logger = LoggerFactory
			.getLogger(pay19ResponseParseStrategy.class);

	private static final int PROCESS_ING = 999;

	public void parseResponse(DealResponse response, int intefaceType) {
		logger.info("New6ResponseParseStrategy parse---{}",
				response.getResContentval());
		if (intefaceType == InterfaceType.QUERY.getValue()) {
			HandleQuery(response);
		} else if (intefaceType == InterfaceType.REQUEST.getValue()) {
			HandleCharge(response);
		}
	}

	private void HandleQuery(DealResponse response) {
		// 解析响应结果 response.getResContentval()
		// response.setDealAmount(dealAmount);
		// response.setErrorCode(errorCode);
		// response.setResCode(resCode);
		// 查询状态成功 经行中就是999 失败就是2 成功是1
		response.setStatus(999);
		response.setRemoteFlg(InterfaceType.QUERY.getValue());
	}

	/**
	 * 请求反馈解析2.00|7696|80d118e519785f0218c7c0c5e96c6245|20130307|
	 * 2013030711304210050|10000|RMB|||||F|11111
	 * 
	 * @param response
	 */
	private void HandleCharge(DealResponse response) {
		// 解析响应结果 response.getResContentval()
		String[] result = response.getResContentval().split("[|]");
		response.setDealAmount(0L);
		response.setErrorCode(result[11] + result[12]);
		response.setResCode(response.getErrorCode());
		response.setSeqId(result[7]);
		// response.setErrorCode(errorCode);
		// response.setResCode("999|" + errorCode);
		// 状态成功就是999 失败就是2 成功是1
//		response.setStatus(PROCESS_ING);
		response.setRemoteFlg(InterfaceType.REQUEST.getValue());
	}
}
